package com.qianfeng.missfood.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.qianfeng.missfood.R;
import com.qianfeng.missfood.category_bean.Category_Detail_Info;
import com.qianfeng.missfood.category_bean.Category_Second_Info;

import java.util.List;

/**
 * Created by Administrator on 2015/8/17.
 */
public class Category_Detail_ptrListView_adapter extends AppBaseAdapter<Category_Detail_Info> {
    private List<Category_Detail_Info> list;
    private BitmapUtils bitmapUtils;
    private Context context;
    public Category_Detail_ptrListView_adapter(List<Category_Detail_Info> list, Context context) {
        super(list, context);
        this.list = list;
        this.context = context;
        bitmapUtils = new BitmapUtils(context);
        bitmapUtils.configDefaultLoadFailedImage(R.mipmap.failed);
        bitmapUtils.configDefaultLoadingImage(R.mipmap.shop_menu_moren_img);
    }


    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.category_detail_ptrlistview_item_layout, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        bitmapUtils.display(holder.thumbUrl_image, list.get(position).getGoodsItem().getPicList().get(0).getThumbUrl());
        holder.name_text.setText(list.get(position).getGoodsItem().getName());
        holder.desc_text.setText("["+list.get(position).getGoodsItem().getDesc()+"]");
        holder.favoriteNum_text.setText(list.get(position).getGoodsItem().getFavoriteNum()+"人收藏");
        holder.shopName_text.setText(list.get(position).getGoodsItem().getShop().getShopName());
        holder.distance_text.setText(list.get(position).getGoodsItem().getShop().getDistance());
        holder.price_text.setText("¥"+Integer.parseInt(list.get(position).getGoodsItem().getPrice())/100);
        return convertView;
    }


    private static class ViewHolder {
       @ViewInject(R.id.thumbUrl_image)
       private ImageView thumbUrl_image;
       @ViewInject(R.id.name_text)
       private TextView name_text;
       @ViewInject(R.id.desc_text)
       private TextView desc_text;
       @ViewInject(R.id.favoriteNum_text)
       private TextView favoriteNum_text;
       @ViewInject(R.id.shopName_text)
       private TextView shopName_text;
       @ViewInject(R.id.distance_text)
       private TextView distance_text;
       @ViewInject(R.id.price_text)
       private TextView price_text;

        public ViewHolder(View convertview) {
            ViewUtils.inject(this, convertview);
        }
    }
}
